package com.hust360.percent.local_db;

import com.hust360.percent.pojo.Area;
import com.hust360.percent.pojo.DiscountInfo;
import com.hust360.percent.pojo.Shop;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class LocalDBHelper extends SQLiteOpenHelper {

	public LocalDBHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		
		/**
		 * 创建本地的shop表
		 */
		db.execSQL("CREATE TABLE Shop(" + 
				"shopId INTEGER PRIMARY KEY," + 
				"shopName VARCHAR(50) NOT NULL," + 
				"brand VARCHAR(30) DEFAULT '未录入', " +
				"address VARCHAR(50) NOT NULL," +
				"totalRate REAL NOT NULL DEFAULT '0'," +
				"telephone VARCHAR(30) DEFAULT '未录入', " +
				"logoPath VARCHAR(50) NOT NULL DEFAULT '', " +
				"longitude REAL, " + 
				"latitude REAL," +
				Shop.CITY_ID + " INTEGER " +
				")");
		
		/**
		 * 创建本地的discountInfo表
		 */
		db.execSQL("CREATE TABLE DiscountInfo( " +
				"discountInfoId INTEGER PRIMARY KEY," +
				"shopId INTEGER NOT NULL," +
				DiscountInfo.AREA_ID_COLUMN + " INTEGER NOT NULL DEFAULT '-1', " +
				"discountInfo VARCHAR(200) NOT NULL DEFAULT '商家没有提供说明'," +
				"discountType INT NOT NULL DEFAULT '1'," +
				"discount INT NOT NULL DEFAULT '0'," +
				"discountImage SMALL TEXT," +
				"liked INTEGER NOT NULL DEFAULT '0'," +
				"type INT NOT NULL DEFAULT '0', " +
				DiscountInfo.BEGIN_DATE_COLUMN + " DATETIME NOT NULL DEFAULT (datetime('now','localtime'))," +
				DiscountInfo.END_DATE_COLUMN + " DATETIME NOT NULL DEFAULT (datetime('now', '+3 day','localtime'))," +
				DiscountInfo.CREATE_DATE_COLUMN + " DATETIME NOT NULL DEFAULT (datetime('now','localtime')) " +
				")");
		
		/**
		 * 创建区域实体的本地数据库缓存表
		 */
		db.execSQL("CREATE TABLE Area(" +
				"id INTEGER PRIMARY KEY, " +
				"shopList SMALL TEXT," +
				"img VARCHAR(255), " +
				"title VARCHAR(100) DEFAULT '未录入'," +
				"fromDate DATETIME NOT NULL DEFAULT (datetime('now','localtime'))," +
				"deadline DATETIME DEFAULT (datetime('now','localtime','+3 days'))," +
				"createDate DATETIME NOT NULL DEFAULT (datetime('now','localtime')), " +
				"type INT NOT NULL," + // 1、百货商城 2、家具家装 3、电器数码、4、美食广场、5娱乐天地
				Area.CITY_ID + " INTEGER" +
				")"
				);
		
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		
	}

	
	
}
